package com.cskaoyan._08game._02pvz;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/6 9:58
 **/
// 定义植物类
public class Plant {
    // 定义成员变量
    String name;
    int price;
    int damage;
    int hp;

    // 持有对方对象(僵尸)的引用
    Zombie zombie;

    public Plant(String name, int price, int damage, int hp) {
        this.name = name;
        this.price = price;
        this.damage = damage;
        this.hp = hp;
    }

    // 定义成员方法
    public void attack() {
        System.out.println(name + "正在攻击" + zombie.name);
    }

    public void beAttacked() {
        System.out.println(name + "正在被" + zombie.name +
                "攻击,血量剩余:" + (hp - zombie.damage));
        // 不要忘记更新血量
        hp = hp - zombie.damage;
    }
}
